package cn.vivi.mapper;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.vivi.domain.User;
import cn.vivi.util.JDBCUtils;

public class UserMapper {

	private QueryRunner runner = JDBCUtils.getQueryRunner();

	public List<User> findAll() throws SQLException {
		return runner.query("select * from user", new BeanListHandler<User>(User.class));
	}

	public User findOne(User user) throws SQLException {
		String sql = "select * from user where username = ? and password = ?";
		return runner.query(sql, new BeanHandler<User>(User.class), user.getUsername(), user.getPassword());
	}

}
